package com.hp.his.basic.web;

import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.hp.his.basic.entity.ExamSummary;
import com.hp.his.basic.entity.Favorite;
import com.hp.his.basic.entity.User;
import com.hp.his.basic.service.UPMSBaseManager;
import com.hp.his.core.util.web.struts2.CrudActionSupport;
import com.opensymphony.xwork2.ActionContext;

@Namespace("/exam")
@Results({    
       @Result(name = CrudActionSupport.RELOAD, location = "list.action", type = "redirect"),
})
public class ListAction extends CrudActionSupport<ExamSummary>{
	
	@Autowired
	private UPMSBaseManager baseManager;
	
	private Integer userId;
	private List<ExamSummary> examList;
	private List<Favorite> favoriteList;

	@Override
	public ExamSummary getModel() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String list() throws Exception {
		ActionContext context = ActionContext.getContext();
		Map session = context.getSession();  
		if(session.get("loggedUser")!=null){
			userId = ((User)session.get("loggedUser")).getUserId();
		}
		
		if(userId != null){
			examList = baseManager.getCreatedExamList(userId);
			favoriteList = baseManager.getFavoriteListByUserId(userId);
		}
		
		return SUCCESS;
	}

	@Override
	public String input() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {		
	
	}


	public List<ExamSummary> getExamList() {
		return examList;
	}

	public void setExamList(List<ExamSummary> examList) {
		this.examList = examList;
	}

	public List<Favorite> getFavoriteList() {
		return favoriteList;
	}

	public void setFavoriteList(List<Favorite> favoriteList) {
		this.favoriteList = favoriteList;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

}
